//
//  EmoticonAttachment.swift
//  表情栏
//
//  Created by Dengdwd on 15/10/21.
//  Copyright © 2015年 dwd. All rights reserved.
//

import UIKit

class EmoticonAttachment: NSTextAttachment {
    
    var chs:String?
    
    init(chs:String) {
        self.chs = chs
        super.init(data: nil, ofType: nil)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    class func getImageText(emotition:Emotition,font:UIFont) ->NSAttributedString {
        let attachment = EmoticonAttachment(chs: emotition.chs!)
        attachment.image = UIImage(contentsOfFile: emotition.imagePath)
        let height = font.lineHeight
        attachment.bounds = CGRect(x: 0, y: -4, width: height, height: height)
        let imageText = NSMutableAttributedString(attributedString: NSAttributedString(attachment: attachment))
        imageText.addAttribute(NSFontAttributeName, value: font, range: NSRange(location: 0, length: 1))
        
        return imageText
    }
}
